<?php
declare(strict_types=1);

namespace WebApp\lib\config;

/**
 * Class Config
 * @package WebApp\lib
 */
class Config{
    private static $config = CONFIG;
    private static $key_val = [];

    /**
     * @param $key
     * @return mixed
     * @internal param $fileName
     */
    public static function getConf($key){
        return self::getVal(self::$config, $key);
    }

    public static function setConf($key, $val){
        self::$config[$key] = $val;
    }

    /**
     * @param $confArr
     * @param $key_str
     * @return mixed
     * @internal param $key
     */
    private static function getVal($confArr, $key_str){
        if (isset(self::$key_val[$key_str])) {
            return self::$key_val[$key_str];
        }
        $keys = explode('.', $key_str);
        $val = $confArr;
        foreach ($keys as $key) {
            if (is_array($val) && isset($val[$key])) {
                $val = $val[$key];
            } else {
                return null;
            }
        }

        self::$key_val[$key_str] = $val;
        return self::$key_val[$key_str];
    }
}